// components/catchform/catchform.js
const app = getApp()
import {
  collect_form_id
} from '../../utils/api.js'

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    carte_id: String,
    button_status: String,
    form_type: Number,
    button_typId: Number,
    button_typTitle: Number,
    switch_id: Number,
    order_type: String
  },

  /**
   * 组件的初始数据
   */
  data: {
    upload: {
      type: Boolean,
      value: true
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //点击即触发获取formId
    catchSubmit: function(e) {
      const that = this
      // console.log(this.data)
      // console.log(e.detail.formId + e.timeStamp)
      if (this.data.upload) {
        try {
          let params = {
            form_id: e.detail.formId,
            uid: app.globalData.userInfo.id,
          }
          // console.log(params)
          app.HttpGetSend(collect_form_id, params, function(res) {
            // console.log(res)
            if (res.msg != "success") {
              // app.showTipMsg(res.msg);
            } else {

            }
          })
        } catch (err) {
          console.log(err)
        }
      }

      //触发回调
      let callback_params = {
        carte_id: this.data.carte_id ? this.data.carte_id : '',
        button_status: this.data.button_status ? this.data.button_status : '',
        button_typId: this.data.button_typId ? this.data.button_typId : '',
        button_typTitle: this.data.button_typTitle ? this.data.button_typTitle : '',
        switch_id: this.data.switch_id ? this.data.switch_id : '', 
        order_type: this.data.order_type ? this.data.order_type : '',
      }
      this.callback(callback_params);
    },
      
    /**
     * 捕获点击回调
     */
    callback: function(params) {
      try {
        this.triggerEvent("callback", params);
      } catch (err) {
        //todo
      }
    }
  }
})